package com.tangtang.core.log;

import org.apache.log4j.Category;
import org.apache.log4j.Priority;
import org.apache.log4j.spi.LoggingEvent;

public class LoggingEventWithReplaceQuote extends LoggingEvent {
    /**
     *
     */
    private static final long serialVersionUID = -470984711722922492L;
    private String threadName;
    private String renderedMessage;

    public LoggingEventWithReplaceQuote(String fqnOfCategoryClass, Category logger,
                                        Priority level, Object message, Throwable throwable) {
        super(fqnOfCategoryClass, logger, level, message, throwable);
    }

    /**
     * @see org.apache.log4j.spi.LoggingEvent#getThreadName()
     */
    @Override
    public String getThreadName() {
        threadName = super.getThreadName();
        if (threadName.indexOf("'") != -1) {
            threadName = threadName.replaceAll("'", "''");
        }
        return threadName;
    }

    /**
     * @see org.apache.log4j.spi.LoggingEvent#getRenderedMessage()
     */
    @Override
    public String getRenderedMessage() {
        renderedMessage = super.getRenderedMessage();

        if (renderedMessage != null && renderedMessage.indexOf("'") != -1)
            renderedMessage = renderedMessage.replaceAll("'", "''");
        return renderedMessage;
    }

}
